package cn.sofwin.day0107.homework;

import java.util.Scanner;

public class Sum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入一个四位数：");
        int number = sc.nextInt();
        if(number > 999 && number < 10000){
            int t = sum(number);
            System.out.println("四位数每位数字之和为：" + t);
        }else{
            System.out.println("输入的数字错误");
        }





    }

    static int sum(int k) {
        int add = 0;
        while (k > 0) {
            add += k % 10;//各位的和
            k /= 10;
        }
        return add;
    }
}
